home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Chans / timeout / timeout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  4.1 KB  |  200 lines

  1. /* timeout.c: message timeout channel */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Chans/timeout/RCS/timeout.c,v 6.0 1991/12/18 20:12:51 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Chans/timeout/RCS/timeout.c,v 6.0 1991/12/18 20:12:51 jpo Rel $
  9.  *
  10.  * $Log: timeout.c,v $
  11.  * Revision 6.0  1991/12/18  20:12:51  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "dbase.h"
  20. #include "qmgr.h"
  21. #include "q.h"
  22. #include "dr.h"
  23. #include "prm.h"
  24.  
  25.  
  26. extern char     *quedfldir;
  27. extern CHAN     *ch_nm2struct();
  28. extern void    sys_init(), rd_end(), err_abrt();
  29. CHAN            *mychan;
  30.  
  31. static struct type_Qmgr_DeliveryStatus *process ();
  32. static int initialise ();
  33. static void dirinit ();
  34. static int security_check ();
  35. static ADDR *get_address ();
  36.  
  37. /*   */
  38. /* main routine */
  39.  
  40. main (argc, argv)
  41. int     argc;
  42. char    **argv;
  43. {
  44.     sys_init(argv[0]);
  45.     dirinit ();
  46. #ifdef PP_DEBUG
  47.     if (argc>1 && (strcmp(argv[1],"debug") == 0))
  48.         debug_channel_control(argc,argv,initialise,process,NULLIFP);
  49.     else
  50. #endif
  51.         channel_control (argc, argv, initialise, process,NULLIFP);
  52. }
  53.  
  54. /*   */
  55. /* routine to move to correct place in file system */
  56.  
  57. static void dirinit ()
  58. {
  59.     if (chdir (quedfldir) < 0)
  60.         err_abrt (RP_LIO, " Unable to change directory to '%s'",
  61.               quedfldir);
  62. }
  63.  
  64. /*   */
  65. /* channel initialise routine */
  66.  
  67. static int initialise (arg)
  68. struct type_Qmgr_Channel *arg;
  69. {
  70.     char *name;
  71.  
  72.     name = qb2str(arg);
  73.  
  74.     if ((mychan = ch_nm2struct(name)) == NULLCHAN) {
  75.         PP_OPER(NULLCP,
  76.             ("Chans/timeout : Channel '%s' not known",name));
  77.         if (name) free(name);
  78.         return NOTOK;
  79.     }
  80.  
  81.     /* check if a timeout channel */
  82.     if (mychan->ch_chan_type != CH_TIMEOUT) {
  83.         PP_OPER(NULLCP,
  84.             ("timeout: Channel '%s' not specified as type timeout",
  85.              name));
  86.         if (name) free(name);
  87.         return NOTOK;
  88.     }
  89.     if (name) free(name);
  90.     return OK;
  91. }
  92.  
  93. /*   */
  94. /* routine called to clean do timeout out */
  95.  
  96. static struct type_Qmgr_DeliveryStatus *process (arg)
  97. struct type_Qmgr_ProcMsg *arg;
  98. {
  99.     struct prm_vars prm;
  100.     Q_struct        que;
  101.     ADDR            *sender;
  102.     ADDR            *recips;
  103.     int             rcount;
  104.     char            *this_msg;
  105.     ADDR            *adr;
  106.  
  107.     prm_init (&prm);
  108.     q_init (&que);
  109.  
  110.     sender = NULLADDR;
  111.     recips = NULLADDR;
  112.  
  113.     delivery_init(arg->users);
  114.     delivery_setall(int_Qmgr_status_messageFailure);
  115.  
  116.     if (security_check(arg) != TRUE)
  117.         return deliverystate;
  118.  
  119.     /* ok-timeout message */
  120.     this_msg = qb2str (arg->qid);
  121.  
  122.     PP_LOG(LLOG_NOTICE,
  123.            ("timing out msg %s", this_msg));
  124.  
  125.     if (rp_isbad(rd_msg(this_msg,&prm,&que,&sender,&recips,&rcount))) {
  126.         PP_LOG(LLOG_EXCEPTIONS,
  127.                ("Chans/timeout rd_msg err: '%s'",this_msg));
  128.         rd_end();
  129.         /* free all storage used */
  130.         if (this_msg != NULL) free(this_msg);
  131.         q_free (&que);
  132.  
  133.         return deliverystate;
  134.     }
  135.  
  136.     for (adr = que.Raddress; adr; adr = adr -> ad_next)
  137.         if (adr -> ad_status == AD_STAT_PEND) 
  138.             set_1dr(&que, adr -> ad_no, this_msg,
  139.                 DRR_UNABLE_TO_TRANSFER,
  140.                 DRD_MAX_TIME_EXPIRED,
  141.                 NULLCP);
  142.     if (arg->users != NULL
  143.         && (adr = get_address(arg->users->RecipientId->parm, &que)) != 0
  144.         && !rp_isbad(wr_q2dr(&que, this_msg)))
  145.          delivery_set(adr -> ad_no, int_Qmgr_status_negativeDR);
  146.     else
  147.         delivery_set(adr -> ad_no, int_Qmgr_status_messageFailure);
  148.  
  149.     /* unlock file */
  150.     rd_end();
  151.  
  152.  
  153.     /* free all storage used */
  154.     if (this_msg != NULL) free(this_msg);
  155.     q_free (&que);
  156.     prm_free(&prm);
  157.  
  158.     return deliverystate;
  159. }
  160.  
  161. /*   */
  162. /* routine to check if allo<wed to timeout this message */
  163. static int security_check (msg)
  164. struct type_Qmgr_ProcMsg *msg;
  165. {
  166.     char *msg_file = NULL, *msg_chan = NULL;
  167.     int result;
  168.  
  169.     result = TRUE;
  170.     msg_file = qb2str (msg->qid);
  171.     msg_chan = qb2str (msg->channel);
  172.  
  173.     if ((mychan == NULLCHAN) || (strcmp(msg_chan,mychan->ch_name) !=0)) {
  174.         PP_LOG(LLOG_EXCEPTIONS,
  175.                ("Chans/timeout channel err: '%s'",msg_chan));
  176.         result = FALSE;
  177.     }
  178.     if (msg_file != NULL) free(msg_file);
  179.     if (msg_chan != NULL) free(msg_chan);
  180.     return result;
  181. }
  182.  
  183. /* routine to extract the required address from the Q_struct */
  184. static ADDR *get_address (usr, que)
  185. int             usr;
  186. Q_struct        *que;
  187. {
  188.     ADDR *ix;
  189.  
  190.     if (usr == 0)
  191.         /* originator */
  192.         return que->Oaddress;
  193.  
  194.     ix = que->Raddress;
  195.     while ((ix != 0) && (--usr > 0))
  196.         ix = ix->ad_next;
  197.  
  198.     return ix;
  199. }
  200.